#include "HelloC.h"

main (int argc, char** argv)
{
    try {
            // Initialize the ORB
        CORBA_ORB_var orb = CORBA::ORB_init(argc, argv);

            // Expect IOR as command-line argument
        if (argc != 2)
        {
            cerr << "Usage: client IOR" << endl;
            throw 0; // neat trick used to exit try block
        }

            // Destringify the IOR
        CORBA::Object_var obj = orb->string_to_object(argv[1]);
        if (CORBA::is_nil(obj))
        {
            cerr << "Nil World reference" << endl;
            throw 0;
        }

            // Narrow an Object to a World
        World_var world = World::_narrow(obj);
        if (CORBA::is_nil(world))
        {
            cerr << "Invalid World reference" << endl;
            throw 0;
        }

            // Say hello to the world
        CORBA::String_var s = world->hello();
        cout << "World said \"" << s << "\"" << endl;
    }
    catch (const CORBA::Exception& e)
    {
        const char* err = e._id();
        cerr << "Client caught CORBA exception: " << err << endl;
        return 100;
    }
    catch (...)
    {
            // Logical error; message already displayed
        return 1;
    }
    return 0;
}

